/*  
	ledDrive.h - an Arduino library for driving led lamps,
	- single LED with fade in and out;
	- RGB LED in single color mode with fade in and out;
	- RGB LED with 5 color rotation with color crossfade     
	- fade is performed with quadratic increment 
	
   Copyright (C) 2014  Gian Luca Rasponi
   
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

//#define LedDebug

#include "Arduino.h"

#ifndef ledDrive_h
#define ledDrive_h

class ledDrive
{
public:
    ledDrive();
    	void singleColor(), RGBcolor();	 
		bool rgbON, manualRgbON, whiteON; // led request status (whiteON also for single led)
		int colorIndex; // color currently output 0 = red .... 4 = purple
		int ledVal[3], fadeIn, crossFade, fadeOut, colorDuration; 
		int white[3], red[3], yellow[3], green[3], blue[3], purple[3]; 
		unsigned long currFadeTime; 
private:
		bool fadeLedNow = 1;
		bool auxON;
		unsigned long prevMillis, ledStartMillis, colorStartMillis, currentMillis;
		int elapsedMillis; 
		int last[3], target[3], lastTarget[3]; // previous target 
		float incr[3]; // RGB fade calculation
		float calcIncrement(int);
		int calcLevel(int);
};

#endif

/* Description of parameters:
**********************************************
Type 	Name ********* 	RGB mode: ***********
bool 	rgbON,				switch on in multi color mode
bool 	manualRgbON 		switch on in single color mode
bool 	whiteON 				switch on in single color mode (also with single led)
int 	colorIndex  		color currently output 0 = red .... 4 = purple
int 	ledVal[3]			R,G,B array output values (0 - 255)
int 	fadeIn				led fade in time (ms)
int 	crossFade			led fade between different colors (ms)
int	fadeOut				led fade out (OFF) time (ms)
int 	colorDuration		duration of each color (sec,)
int 	white[3]				R,G,B preset in single color mode (use white[0] in single mode)
int 	red[3], yellow[3], green[3], blue[3], purple[3]; 
								R,G,B arrays for multi color mode
*/
